
package com.i3q360.layui.modular.system.web;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.i3q360.layui.common.base.BaseController;
import com.i3q360.layui.common.util.PageInfo;
import com.i3q360.layui.modular.system.entity.SysRole;
import com.i3q360.layui.modular.system.service.RoleService;

@Controller
@RequestMapping("/role")
public class RoleController extends BaseController{
		
		@Autowired
		RoleService roleService;
		
		String PREFIX = "/admin/system/";
		
		@RequestMapping("")
		public String index(){
			return PREFIX+"role.html";
		}	

		@RequestMapping("/role-add")
		public String add(){
			return PREFIX+"role-info.html";
		}
		
		@RequestMapping("/role-edit")
		public String edit(@RequestParam(required=true) Integer id,Model model){
			
			model.addAttribute("role", roleService.queryById(id));
			
			return PREFIX+"role-info.html";
		}
		
		@ResponseBody
		@RequestMapping("/page")
		public List<SysRole> page(@RequestParam Map<String,Object> map ){
			
			return roleService.queryList(map);
		}
		
		
		
		/**
		 * 添加菜单
		 */
		@ResponseBody
		@RequestMapping("/save")
		public boolean  add(SysRole menu){
			roleService.save(menu);
			return true;
		}
 		
		@ResponseBody
		@RequestMapping(value="/delete",method=RequestMethod.POST)
		public boolean delete(SysRole role){
			if(role.getId()==null)
				return false;
			//判断是否是管理员
			role = roleService.queryById(role.getId());
			if("admin".equals(role.getRole())){
				return false;
			}
			roleService.delete(role);
			return true;
		}
		
}
